# -*- coding: utf-8 -*-
# @Time    : 2022/7/16 9:59
# @Author  : clm
# @Email   : 2894940379@qq.com
# @File    : mail_moban_page.py
# @Software: PyCharm
from pages.send_mail_page import SendMailePage
from selenium.webdriver.common.by import By


class MaileMobanPage(SendMailePage):
    url = "http://localhost/crm/index.php?m=email&a=index"
    select_delete_moban_locator = (By.CSS_SELECTOR, "#form1 > div:nth-child(2) > table > tbody > tr:nth-child(1) > td:nth-child(1) > input")
    click_delete_locator = (By.ID, "btn_delete")
    add_email_locator = (By.CSS_SELECTOR, "#add")
    ztk_locator = (By.CSS_SELECTOR, "#dialog-edit")
    moban_name_locator = (By.CSS_SELECTOR, "#dialog-add > form > table > tbody > tr:nth-child(2) > td:nth-child(2) > input")
    mail_title_locator = (By.NAME, "title")
    mail_content_locator = (By.CSS_SELECTOR, "#content")
    select_moban_locator = (By.CSS_SELECTOR, "#form1 > div:nth-child(2) > table > tbody > tr:nth-child(1) > td:nth-child(1) > input")
    click_edit_locator = (By.CSS_SELECTOR, "#form1 > div:nth-child(2) > table > tbody > tr:nth-child(1) > td:nth-child(5) > a")
    edit_name_locator = (By.NAME, "subject")
    edit_title_locator = (By.NAME, "title")
    edit_content_locator = (By.NAME, "content")
    click_save_locator = (By.NAME, "submit")

    def click_delete_moban(self):
        """点击要删除的模板"""
        self.driver.find_element(*self.select_delete_moban_locator).click()

    def click_delete(self):
        """点击删除"""
        self.driver.find_element(*self.click_delete_locator).click()
        self.driver.switch_to.alert.accept()

    def click_add_email(self):
        """点击添加邮件模板"""
        self.driver.find_element(*self.add_email_locator).click()

    def click_ztK(self):
        """点击添加邮件模板的整体框"""
        self.driver.find_element(*self.ztk_locator).click()

    def input_name(self, name):
        """输入模板名称"""
        self.driver.find_element(*self.moban_name_locator).send_keys(name)

    def input_title(self, title):
        """输入邮件主题"""
        self.driver.find_element(*self.mail_title_locator).send_keys(title)

    def input_content(self, content):
        """输入邮件内容"""
        self.driver.find_element(*self.mail_content_locator).send_keys(content)

    def select_moban(self):
        """勾选要编辑的模板"""
        self.driver.find_element(*self.select_moban_locator).click()

    def click_edit(self):
        """点击编辑"""
        self.driver.find_element(*self.click_edit_locator).click()
    def edit_name(self,name):
        """修改邮件模板名称"""
        self.driver.find_element(*self.edit_name_locator).clear()
        self.driver.find_element(*self.edit_name_locator).send_keys(name)
    def edit_title(self,title):
        """修改邮件主题"""
        self.driver.find_element(*self.edit_title_locator).clear()
        self.driver.find_element(*self.edit_title_locator).send_keys(title)
    def edit_content(self,content):
        """修改邮件内容"""
        self.driver.find_element(*self.edit_content_locator).clear()
        self.driver.find_element(*self.edit_content_locator).send_keys(content)

    def click_save(self):
        """点击保存"""
        self.driver.find_element(*self.click_save_locator).click()
